package cn.jksoft.businessclient.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.jksoft.businessclient.R;
import cn.jksoft.businessclient.base.BaseSwipeBackCompatActivity;
import cn.jksoft.businessclient.ui.adapter.FragmentAdapter;
import cn.jksoft.businessclient.ui.fragment.AllOrderFragment;
import cn.jksoft.businessclient.ui.fragment.ServiceRunningFragment;
import cn.jksoft.businessclient.ui.fragment.WaitConfirmFragment;

/**
 * Created by RogersHuang on 16/4/12.
 */
public class OnlineOrderActivity extends BaseSwipeBackCompatActivity{
    @Bind(R.id.tabs)
    TabLayout mTabLayout;

    @Bind(R.id.viewpager)
    ViewPager mViewPager;

    private WaitConfirmFragment waitConfirmFragment;
    private ServiceRunningFragment serviceRunningFragment;
    private AllOrderFragment allOrderFragment;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_online_order);
        ButterKnife.bind(this);
        initTitle("线上服务");
        initBackClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initFragments();
        initViewPager();
    }

    private void initFragments() {
        waitConfirmFragment = new WaitConfirmFragment();
        serviceRunningFragment = new ServiceRunningFragment();
        allOrderFragment = new AllOrderFragment();
    }

    private void initViewPager() {
        ArrayList<String> titles = new ArrayList<>();
        titles.add("待确认");
        titles.add("服务中");
        titles.add("全部");
        for(int i=0;i<titles.size();i++){
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(waitConfirmFragment);
        fragments.add(serviceRunningFragment);
        fragments.add(allOrderFragment);
        FragmentAdapter mFragmentAdapteradapter =
                new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        mViewPager.setAdapter(mFragmentAdapteradapter);
        mViewPager.setOffscreenPageLimit(3);
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
    }
}
